<?php 
	require_once('config.php'); 
	require_once('functions.php');
	dbconnect();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
<?php
		/* Filter Handling */
		/* If a JobType filter is given, then limit the results to the jobs with the correcponding type_id */
		$sql="SELECT job_id, job_title, job_description, job_city, job_state from wms_job";
		$added_where = false;
		
		if($_POST["Duration"] || $_POST["City"] || $_POST["State"] || $_POST["Type"] != 0)
		{
			if($_POST["Type"] != 0) {
				$sql = $sql." where job_type = ".$_POST["Type"];
				$added_where = true;
			}
			
			if($_POST["Duration"]){
				if($added_where) {
					$sql = $sql." and ";
				}else{
					$sql = $sql." where ";
					$added_where = true;
				}
				$sql = $sql."perm_temp = \"".$_POST["Duration"]."\"";
			}
			
			if($_POST["State"]){
				if($added_where) {
					$sql = $sql." and ";
				}else{
					$sql = $sql." where ";
					$added_where = true;
				}
				$sql = $sql."job_state = \"".$_POST["State"]."\"";
			}
		
			if($_POST["City"]){
				if($added_where) {
					$sql = $sql." and ";
				}else{
					$sql = $sql." where ";
					$added_where = true;
				}
				$sql = $sql."job_city = \"".$_POST["City"]."\"";
			}
		}
		
		//echo $sql;
		$result=mysql_query($sql);
		
		$table_stuff="<tr><td width=\"150\"></td><td width=\"150\">Job Title</td><td width=\"550\">Job Description</td><td width=\"120\">Job City</td><td width=\"120\">Job State</td></tr>";
		
		while ($row=mysql_fetch_array($result)) {
			$id=$row["job_id"];
			$title=$row["job_title"];
			$desc=$row["job_description"];
			$city=$row["job_city"];
			$state=$row["job_state"];
			$table_stuff.="<tr><td><form action=\"singlejob.php\" method=\"post\"><input type=\"hidden\" name=\"Job_ID\" value=\"".$id."\" /><button name=\"Abutton2\">More Info</button></form></td><td>".$title."</td><td align=\"left\">".$desc."</td><td>".$city."</td><td>".$state."</td></tr>\n";
		}
		
		echo $table_stuff;
	?>
</body>

</html>
